#include "Color.h"
#include "Arduino.h"

Color::Color(int R, int G, int B)
{
  this->R = R;
  this->G = G;
  this->B = B;
}

int Color::ToIntM(char *arr)
{
  String a = "";
  for (int i = 1; i < 4; i++)
    a = a + arr[i];
  return a.toInt();
}

void Color::SetColor(char* colorStr)
{
  int value = ToIntM(colorStr);
  Serial.println(value);
  switch (colorStr[0])
  {
    case 'R' | 'r':
      Serial.println("R");
      analogWrite(9, value);
      break;
    case 'G' | 'g':
      Serial.println("G");
      analogWrite(10, value);
      break;
    case 'B' | 'b':
      Serial.println("B");
      analogWrite(11, value);
      break;
    default:
      break;
  }
}

void Color::GetString() {
  int index = 0;
  char arr[5];
  if (Serial.available() > 0) {
    while (true) {
      if (index == 4) {
        SetColor(arr);
        break;
      }
      arr[index] = Serial.read();
      index++;
    }
  }
  delay(1000);
}
